Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve BLE reliability #269

Merged

Conversation

sethterashima
Copy link
Collaborator

@sethterashima sethterashima commented Jul 2, 2024

Description

Improve BLE connection reliability:

  • Increase timeouts for BLE dialer and listener
  • Retry initial connection on non-fatal errors until context expires
  • Tweak scanning interval to reflect BLE advertisement parameters

Future improvements (deferred to get the existing improvements merged sooner):

  • Retry connection using client MAC address instead of scanning
  • Optimize scanning interval
  • Adjust timeouts using caller context

Fixes #253

Type of change

Please select all options that apply to this change:

  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Bug fix (non-breaking change which fixes an issue)
  • Documentation update

Checklist:

Confirm you have completed the following steps:

  • My code follows the style of this project.
  • I have performed a self-review of my code.
  • I have made corresponding updates to the documentation.
  • I have added/updated unit tests to cover my changes.

@iainwhyte
Copy link

tested an RPi4 with built in Bluetooth today to a 2021 M3 and could not fault it. about 25 commands, no timeouts. This seems heaps better. It also seems faster as well.

@wimaha
Copy link

wimaha commented Jul 5, 2024

Tested on RPI3+ with built in bluetooth and it is working very good! Thank you for your effort.

 - Increase timeouts for BLE dialer and listener
 - Retry initial connection on non-fatal errors until context expires
 - Tweak scanning interval to reflect BLE advertisement parameters

Ideas for future improvements:

 - Retry connection using client MAC address instead of scanning
 - Optimize scanning interval
 - Adjust timeouts using caller context
@sethterashima sethterashima changed the title [Draft] Improve BLE reliability Improve BLE reliability Jul 25, 2024
@sethterashima sethterashima merged commit eaf6ee1 into teslamotors:main Jul 31, 2024
1 check passed
@BogdanDIA
Copy link

I wrote this in #253 but since it is closed, I also write it here.

Tested the new code with several adapters I have. It works a bit faster for BT 5.0 adapter but it broke the BT4.x support. That is due to using the Extended Adv features that were introduced starting with BT 5.0 and not known for the BT4.2 adapter I have.

vehicle-command/pkg/connector/ble/device_linux.go

var scanParams = cmd.LESetScanParameters{
LEScanType: 1, // Active scanning
LEScanInterval: 0x10, // 10ms
LEScanWindow: 0x10, // 10ms
OwnAddressType: 0, // Static
ScanningFilterPolicy: 2, // Basic filtered <- this should be 0 for Basic Filtered.
}

Here are the possible values:
0x00 Basic unfiltered scanning filter policy
0x01 Basic filtered scanning filter policy
0x02 Extended unfiltered scanning filter policy <- added in 5.0
0x03 Extended filtered scanning filter policy <- added in 5.0

If it is really needed to use the extended features from BT5.x it can be possible to request the local adapter BT version in the beginning of the handshake so the BLE can use ScanningFilterPolicy: 0 when the BT version is below 5.0. I see go-ble package has the function ReadLocalVersionInformation available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

send ATT request failed: io: read/write on closed pipe every 30 seconds
5 participants